package control
{
   import flash.display.BlendMode;
   import flash.display.LoaderInfo;
   import flash.display.MovieClip;
   import flash.geom.Rectangle;
    import flash.events.Event;

   public class CropBound extends ScaleBound
   {
      private var cropmc: MovieClip = new MovieClip
      private var darkmc: MovieClip = new MovieClip
      private var _bound: Rectangle

      public function CropBound(bound:Rectangle=null, rect:Rectangle=null, markerCount:int=8) 
      {
         super(rect, markerCount);
         _bound = bound
      }

      override protected function init (event:Event=null): void 
      {
         darkmc.graphics.beginFill(0xFFFFFF, 0.2)
         darkmc.blendMode = BlendMode.ADD
         darkmc.graphics.drawRect(0, 0, 100, 100)
         darkmc.graphics.endFill()

         cropmc.graphics.beginFill(0xFF0000, 0.3)
         cropmc.graphics.drawRect(0, 0, 100, 100)
         cropmc.graphics.endFill()
         addChildAt(cropmc, 0)
         cropmc.mask = darkmc 
         
         addChildAt(darkmc, 0)
         super.init()
      }


      override protected function drawBound (): void {
         super.drawBound()

         _rect.x += _bound.x - darkmc.x
         _rect.y += _bound.y - darkmc.y

         cropmc.x = _rect.x
         cropmc.y = _rect.y
         cropmc.width = _rect.width
         cropmc.height = _rect.height

         darkmc.x = _bound.x
         darkmc.y = _bound.y
         darkmc.width = _bound.width
         darkmc.height = _bound.height
      }


      public function set bound (value:Rectangle): void {
         _bound = value
         drawBound()
      }


      public function get bound (): Rectangle {
         return _bound
      }


      override public function set rect(value:Rectangle):void {
         _rect = value
         _rect.x += _bound.x
         _rect.y += _bound.y
         drawBound()
      }


      override public function get rect (): Rectangle {
         var result: Rectangle = _rect.clone()
         result.x -= _bound.x
         result.y -= _bound.y
         return result
      }

   }
}